import sys

import numpy as np

from common.reversible_dict import ReversibleDict


def initData(data):
    edges = data['edges']
    nodes_data = data['nodesData']
    start_node = data['startNode']
    goal_node = data['targetNode']
    key_nodes = data['keyNodes']
    cost_v = data['costV'][0]
    dim_n = len(nodes_data)
    dim_k = len(data['keyNodes'])
    dim_c = 1
    is_key = list(np.full(dim_n, False))
    for i in range(dim_n):
        if i in key_nodes:
            is_key[i] = True

    cost_e = data['cost'][0]
    for i in range(cost_e.shape[0]):
        for j in range(cost_e.shape[1]):
            if cost_e[i][j] <= 0:
                cost_e[i][j] = 99999999
    node_index_dict = {v: k for k, v in data['nodesData'].items()}
    node_edge_dict = {**data['nodesData'], **{(int(k.split(',')[0]), int(k.split(',')[1])) :v for k, v in data['edgesData'].items()}}

    return dim_n, dim_k, dim_c, start_node, goal_node, is_key, edges, cost_v, cost_e, node_index_dict, node_edge_dict

# # 您的 JSON 数据
# json_data = '''
# {
#     "startNode": {"id": "node-4208", "preNodeType": "device-node"},
#     "targetNode": {"id": "node-6000", "preNodeType": "device-node"},
#     "nodes": [
#         // ... 节点数据 ...
#     ],
#     "edges": [
#         // ... 边数据 ...
#     ]
# }
# '''

# # 调用函数进行转换  
# dim_n, dim_k, dim_c, start_node, goal_node, T, F, is_key, edges, cost_v, cost_e = convert_json_to_custom_structure(
#     json_data)
# 
# # 打印结果  
# print("dim_n:", dim_n)
# print("dim_k:", dim_k)
# print("dim_c:", dim_c)
# print("start_node:", start_node)
# print("goal_node:", goal_node)
# print("is_key:", is_key)
# print("edges:")
# for row in edges:
#     print(row)
# print("cost_v:", cost_v)
# print("cost_e:")
# for row in cost_e:
#     print(row)
